using System;
using System.Collections.Generic;
using System.Text;

using System.Management.Automation;

namespace Microsoft.PowerShell.CmdletManagement
{
    [Cmdlet(VerbsCommon.Get, "PsSpecCmdletParameterSetEntry")]
    public class GetPsSpecCmdletParameterSetEntryCommand : Cmdlet
    {
        [Parameter(Mandatory = false, Position = 0, ValueFromPipelineByPropertyName = true)]
        [ValidateLength(1, 50)]
        public String ParameterSetName
        {
            get
            {
                return _parameterSetName;
            }
            set
            {
                _parameterSetName = value;
            }
        }
        private string _parameterSetName = "*";

        [Parameter(Mandatory = false, Position = 1, ValueFromPipelineByPropertyName = true)]
        [ValidateLength(1, 50)]
        public String ParameterName
        {
            get
            {
                return _parameterName;
            }
            set
            {
                _parameterName = value;
            }
        }
        private string _parameterName = "*";

        [Parameter(Mandatory = false, Position = 2, ValueFromPipelineByPropertyName = true)]
        [ValidateLength(1, 50)]
        public String CmdletName
        {
            get
            {
                return _cmdletName;
            }
            set
            {
                _cmdletName = value;
            }
        }
        private string _cmdletName = "*";

        [Parameter(Mandatory = false, Position = 3, ValueFromPipelineByPropertyName = true)]
        [ValidateLength(1, 50)]
        public String ProjectName
        {
            get
            {
                return _projectName;
            }
            set
            {
                _projectName = value;
            }
        }
        private string _projectName = "*";

        [Parameter(Mandatory = false)]
        public String ServiceUri
        {
            get
            {
                return _serviceUri;
            }
            set
            {
                _serviceUri = value;
            }
        }
        private string _serviceUri = PsSpecCmdletUtils.Constants.ServiceUri;


        protected override void ProcessRecord()
        {
            PsSpecCmdletService.PsSpecCmdletParameterSetEntry[] parameterSetEntries = null;

            PsSpecCmdletService.CmdletService service =
                new PsSpecCmdletService.CmdletService();
            service.Url = ServiceUri;

            service.UseDefaultCredentials = true;

            parameterSetEntries = service.GetPsSpecCmdletParameterSetEntry(
                PsSpecCmdletUtils.ConvertWildcardToSqlWildcard(ProjectName),
                PsSpecCmdletUtils.ConvertWildcardToSqlWildcard(CmdletName),
                PsSpecCmdletUtils.ConvertWildcardToSqlWildcard(ParameterName),
                PsSpecCmdletUtils.ConvertWildcardToSqlWildcard(ParameterSetName));

            foreach (PsSpecCmdletService.PsSpecCmdletParameterSetEntry parameterSetEntry in parameterSetEntries)
            {
                WriteObject(new PsSpecCmdletParameterSetEntry(
                        parameterSetEntry.Id,
                        parameterSetEntry.ParameterSetName, parameterSetEntry.ParameterName, parameterSetEntry.CmdletName,
                        parameterSetEntry.ProjectName, parameterSetEntry.Mandatory, parameterSetEntry.Position,
                        parameterSetEntry.ValueFromPipeline, parameterSetEntry.ValueFromPipelineByPropertyName,
                        parameterSetEntry.ValueFromRemainingArguments, parameterSetEntry.HelpMessage,
                        parameterSetEntry.HelpMessageBaseName, parameterSetEntry.HelpMessageResourceId,parameterSetEntry.ParameterId));
            }
        }
    }
}
